
import sys

def count_characters(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        text = file.read()
        return len(text)

def count_words(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        text = file.read()
        words = text.split()
        return len(words)

def count_sentences(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        text = file.read()
        sentences = text.split('. ')
        return len(sentences)

def count_lines(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        return len(lines)

def count_code_lines(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        code_lines = 0
        for line in lines:
            line = line.strip()
            if line and not line.startswith('#'):
                code_lines += 1
        return code_lines

def count_blank_lines(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        blank_lines = 0
        for line in lines:
            if not line.strip():
                blank_lines += 1
        return blank_lines

def count_comment_lines(file_name):
    with open(file_name, 'r', encoding='utf-8') as file:
        lines = file.readlines()
        comment_lines = 0
        for line in lines:
            line = line.strip()
            if line.startswith('#'):
                comment_lines += 1
        return comment_lines

if len(sys.argv) != 3:
    print("命令模式: v03.py [参数r] [文件名]")
    sys.exit(1)

option = sys.argv[1]
file_name = sys.argv[2]

if option == '-c':
    print("字符数:", count_characters(file_name))
elif option == '-w':
    print("单词数:", count_words(file_name))
elif option == '-s':
    print("句子数:", count_sentences(file_name))
elif option == '-l':
    print("行数:", count_lines(file_name))
elif option == '-cl':
    print("代码行数:", count_code_lines(file_name))
elif option == '-bl':
    print("空行数:", count_blank_lines(file_name))
elif option == '-coml':
    print("注释行数:", count_comment_lines(file_name))
else:
    print("无效的参数")